#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    int cnt = 0;
    int time = 0;
    while (n) {
        int id, h, m;
        char op;
        scanf("%d %c %d:%d", &id, &op, &h, &m);
        int calTime = h * 60 + m;
        if (id) {
            if (op == 'S') {
                mp[id] = calTime;
            } else if (op == 'E' && mp.find(id) != mp.end()){
                int delta = calTime - mp[id]; // 阅读时间
                time += delta;
                cnt++;
                auto iter = mp.find(id); 
                mp.erase(iter);
            }
            
        } else {
        // 结束一天操作
            n--;
            if (cnt != 0) 
                cout << cnt << " "<< (int)(time * 1.0 / cnt + 0.5) << endl;
            else 
                cout << 0 <<  " " << 0 << endl;
            cnt = 0;
            time = 0;
            mp.clear();
        }
    }
    return 0;
}